/* ========================================
* 
* file:		thread_pool.h
* brief:	
* author:	catlovefish
* version:	1.0.0
* date:		2015-03-04 17:04:53
* 
* ========================================*/
#ifndef THREAD_POOL_H
#define THREAD_POOL_H
#include <vector>
#include <list>
#include <thread>
#include <mutex>
#include <functional>

typedef std::function<void (void)> ThreadTask;

class ThreadPool
{
public:
	ThreadPool(int nPoolSize = 1, int nQueueSize = 0);

	void start();

	void runTask();

	void stop();

	void setQueueSize(int nSize);

protected:
	void entry();

private:
	int						pool_size_;
	int						queue_size_;
	bool					stop_;

	std::vector<std::thread*>		thread_list_;
	std::list<ThreadTask>	task_list_;
	std::mutex				not_full_mutex_;
	std::mutex				not_empty_mutex_;
};

#endif
